﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SYT.AliApiHandle
{
    //帮助方法类
    public class HelpMethod
    {
        //计算产品的价格信息，返回最高价格。
        public static string UpdateProShowPrice(ArrayList arrayList)
        {
            List<float> floatArray = new List<float>();

            //System.Collections.ArrayList arrayList = (System.Collections.ArrayList)(saleInfo["priceRanges"]);
            if (arrayList != null && arrayList.Count > 0)
            {
                foreach (var price in arrayList)
                {
                    Hashtable newprice = (Hashtable)price;
                    float Price1 = float.Parse(newprice["price"].ToString());
                    floatArray.Add(Price1);
                }

                return floatArray.Max().ToString();
            }
            else
            {
                return "暂无价格";
            }
        }


        //获取商品的第一张图片
        public static string Firstimage(ArrayList arrayList)
        {
            if (arrayList != null)
            {
                foreach (var item in arrayList)
                {
                    return "https://cbu01.alicdn.com/" + ((Hashtable)item)["imageURI"].ToString();
                }
                return "/Theme/image/Is_no_image80x80.jpg";

            }
            else
            {
                return "/Theme/image/Is_no_image80x80.jpg";
            }
        }

        // 将字符串转换为日期
        public static string ConvertTimeA(string strtime)
        {
            strtime = strtime.Substring(0, 4) + "-" + strtime.Substring(4, 2) + "-" + strtime.Substring(6, 2);

            return strtime;
        }

        // 将字符串转换为日期
        public static string ConvertTimeB(string strtime)
        {
            if (!string.IsNullOrEmpty(strtime))
            {
                string Timeystr = DateTime.Parse(strtime).ToString("yyyyMMdd");
                string Timestr = "000014384+0800";
                return Timeystr + Timestr;
            }
            return "";
        }
    }

}
